mt_rand()
uses the Mersenne Twister algorithm to return random integers.
In this example, we will return some random numbers:
<?php echo ( mt_rand ( ) ) ; echo ( mt_rand ( ) ) ; echo ( mt_rand ( 10 , 100 ) ) ; ?>
Try it yourself
mt_rand ( min , max )
If no optional parameters min and max are provided, mt_rand() returns a pseudo-random number between 0 and RAND_MAX. For example, if you want a random number between 5 and 15 (including 5 and 15), use mt_rand(5, 15).
Many old libc random number generators have some uncertain and unknown characteristics and are very slow. The rand() function of PHP uses the libc random number generator by default. mt_rand()
function is used informally to replace it. This function uses a known feature in Mersenne Twister as a random number generator, which can produce random values at an average speed of four times faster than rand()
provided by libc.